/*  
	 ___                         
	/\_ \    __                  
	\//\ \  /\_\  __  __    __   
	  \ \ \ \/\ \/\ \/\ \ /'__`\ 
	   \_\ \_\ \ \ \ \_/ |\  __/ 
	   /\____\\ \_\ \___/\ \____\
	   \/____/ \/_/\/__/  \/____/ v1.8.9
                             
	A lightweight Javascript interface with various extensions
	Max Felker | max@bigroomstudios.com
	Brian Leighton | max@bigroomstudios.com
	
	+1 Google for the Closure Compiler | http://closure-compiler.appspot.com/home
	
	ASCII Art Generated @ http://patorjk.com/software/taag/
	
*/

// START Class
var live = Class.create({

	initialize: function(config) {

		config.page ? this.page = config.page: this.page = window.location;
		config.browser ? this.browser = config.browser: this.browser = Prototype.Browser;

		this.rollovers = $H();
		this.popups = $H();
		this.dropdowns = $H();
		this.tooltips = $H();
		this.forms = $H();
 
		this.regex = $H({
			empty: '',
			all: /^.*$/,
			bit: /^(0|1)$/, 
			num: /^-?([0-9]*)$/,
			alpha: /^[a-zA-z\s]+$/,
			alphanum:  /^[a-zA-Z0-9]?[\s||\'||\"||\.||\?||\!||\-||a-zA-Z0-9]+$/,
			email: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
			phone: /^([0-9]{3}( |-|.)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-|.)?([0-9]{3}( |-|.)?[0-9]{4}|[a-zA-Z0-9]{7})$/,
			cc: /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/,
			zip: /^(([0-9]{5})|([0-9]{5}[-][0-9]{4}))$/,
			decimal: /^\d+\.\d{0,4}$/,
			price: /^\$?\s?[0-9\,]+(\.\d{0,4})?$/
		});

		document.on("dom:loaded", function() {
	
			this.init_dom();
			
			this.init_ui();
				
		}.bind(this));


	},

	init_ui: function() {

		this.keys = new Keys();

		this.canopy = new Canopy();

		this.modal = new Modal();

		this.time = new Time();	
		
		this.loader = new Loader();
		
	},
	
	init_dom: function() {
	
		this.html = $$("html")[0];
		this.head = $$("head")[0];
		this.body = $(document.body);	
	
		document.on('mousemove', this.get_mouse_position.bind(this));					

		this.get_viewport_dimensions();
		this.get_viewport_offset();
		
		Event.on(window,'resize', this.get_viewport_dimensions.bind(this));
		Event.on(window,'scroll', this.get_viewport_offset.bind(this));
	
	},
	
	get_viewport_dimensions: function() {
	
		this.viewport = document.viewport.getDimensions();
	
	},
	
	get_viewport_offset: function() {

		this.viewport_offset = document.viewport.getScrollOffsets();
	
	},
	
	get_mouse_position: function(e) {
		
		this.mouse = Event.pointer(e);

	},
	
	create_js: function(src) {
	  
		if(src && src.endsWith(".js")) {
		  
			var new_js = new Element("script", {
				type: "text/javascript",
				src: src
			});
			
			this.head.appendChild(new_js);
			
		} else {
		  
			return false;	
				
		}
		
	},

	create_css: function(href) {
	  
		if(href && href.endsWith(".css")) {
		  
			var new_css = new Element("link", {
				rel: "stylesheet",
				type: "text/css",
				href: href
			});
			
			this.head.appendChild(new_css);
			
		} else {
		  
			return false;
			
		}
		
	},
	
	print_page: function(src) {
	
		if(!src) {
			window.print();
			return false;
		}

		this.print_popup = new Popup({
			src:src,
			container: 'print',
			height:1,
			width:1,
			title_height:0
		});
		
		this.print_popup.container.setStyle('top:-1000px;left:-1000px;');
		
		this.print_popup.controls_container.hide();
		
		this.print_popup.iframe.on('load',function() {
		
			this.print_popup.iframe = document.frames ? document.frames[this.print_popup.iframe.id] : document.getElementById(this.print_popup.iframe.id);
		
			this.print_popup.print_window = this.print_popup.iframe.contentWindow || this.print_popup.iframe;
			this.print_popup.iframe.focus();
			
			this.print_popup.print_window.print();
			
			this.print_popup.remove_popup();
			
		}.bind(this));
		
		return false;
	
	}
	
}); 
// END Class
